package spring_learn.a05;

import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ConfigurationClassPostProcessor;
import org.springframework.context.support.GenericApplicationContext;
import spring_learn.a05.myProcessor.BeanPostProcessor;
import spring_learn.a05.myProcessor.ComponentScanPostProcessor;
import spring_learn.a05.myProcessor.MapperPostProcessor;


/*
        BeanFactory后处理器的作用
 */
@SpringBootApplication
public class A05 {

    public static void main(String[] args) {
        GenericApplicationContext genericApplicationContext=new GenericApplicationContext();
        genericApplicationContext.registerBean(Config.class);

        //添加bean factory后处理器
        //处理@ComponentScan @Bean @Import @ImportResource
        //genericApplicationContext.registerBean(ConfigurationClassPostProcessor.class);
        //处理@MapperScanner
        /*genericApplicationContext.registerBean(MapperScannerConfigurer.class, bd -> {
            bd.getPropertyValues().add("basePackage","spring_learn.a05.mapper");
        });*/

        //自定义
        //处理componentScan
        genericApplicationContext.registerBean(ComponentScanPostProcessor.class);
        //处理bean
        genericApplicationContext.registerBean(BeanPostProcessor.class);
        //处理mapper
        genericApplicationContext.registerBean(MapperPostProcessor.class);
        genericApplicationContext.refresh();
        String[] beanDefinitionNames = genericApplicationContext.getBeanDefinitionNames();
        for (String beanDefinitionName : beanDefinitionNames) {
            System.out.println(beanDefinitionName);
        }
        genericApplicationContext.close();
    }
}
